import {
  get,
  post,
  put,
  del
} from "./base_service"

/**
 * 房源发布相关接口
 * 1.房源发布
 * 2.房源回填
 * 3.房源更新
 * 
 * allen  2021-08-02
 */


/**
 * 创建新房基础数据
 * @param {*} data 
 */
const createNewHouseBasicInfo = (data) => {
  console.log("JJLog:新房基本数据JSON:" + JSON.stringify(data));
  return new Promise((resolve, reject) => {
    post("/new/house/manager/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 新房图片数据
 * @param {*} data 
 */
const createNewHouseImgList = (data) => {
  console.log("JJLog:新房图片JSON:" + JSON.stringify(data));
  return new Promise((resolve, reject) => {
    post("/new/house/image/manager/create/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 新房基本信息回填
 * @param {*} houseNumber 
 */
const queryNewHouseBasicInfo = (houseNumber) => {
  return new Promise((resolve, reject) => {
    get("/new/house/manager/detail?houseNumber=" + houseNumber).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新房源基本信息
 * @param {*} data 
 */
const updateNewHouseBasicInfo = (data) => {
  return new Promise((resolve, reject) => {
    put("/new/house/manager/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 查询新房所有图片
 * @param {*} houseNumber 
 */
const queryNewHouseImgList = (houseNumber) => {
  return new Promise((resolve, reject) => {
    get("/new/house/image/manager/list?houseNumber=" + houseNumber).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 新房的户型列表
 * @param {*} houseNumber 
 */
const queryNewHouseFormatList = (houseNumber) => {
  return new Promise((resolve, reject) => {
    get("/new/house/format/manager/list?houseNumber=" + houseNumber).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 根据id查询户型的一个详情
 * @param {*} id 
 */
const queryNewHouseFormatDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/new/house/format/manager/detail?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建一个新房的户型
 * @param {*} data 
 */
const createNewHouseFormat = (data) => {
  return new Promise((resolve, reject) => {
    post("/new/house/format/manager/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新一个户型信息
 * @param {*} data 
 */
const updateNewHouseFormat = (data) => {
  return new Promise((resolve, reject) => {
    put("/new/house/format/manager/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 删除一条户型数据
 * @param {*} id 
 */
const deleteNewHouseFormat = (id) => {
  return new Promise((resolve, reject) => {
    del("/new/house/format/manager/delete?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 新房楼栋列表查询
 * @param {*} houseNumber 
 */
const queryNewHouseFloorList = (houseNumber) => {
  return new Promise((resolve, reject) => {
    get("/new/house/flat/manager/list?houseNumber=" + houseNumber).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 删除一个新房楼栋
 * @param {*} id 
 */
const deleteNewHouseFloor = (id) => {
  return new Promise((resolve, reject) => {
    del("/new/house/flat/manager/delete?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建一个新房楼栋
 * @param {*} data 
 */
const createNewHouseFloor = (data) => {
  return new Promise((resolve, reject) => {
    post("/new/house/flat/manager/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 获取一个楼栋的详情
 * @param {*} id 
 */
const queryNewHouseFloorDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/new/house/flat/manager/detail?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新一个楼栋信息
 * @param {*} data 
 */
const updateNewHouseFloor = (data) => {
  return new Promise((resolve, reject) => {
    put("/new/house/flat/manager/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}









module.exports = {
  createNewHouseBasicInfo,
  createNewHouseImgList,
  queryNewHouseBasicInfo,
  updateNewHouseBasicInfo,
  queryNewHouseImgList,
  queryNewHouseFormatList,
  queryNewHouseFormatDetail,
  createNewHouseFormat,
  updateNewHouseFormat,
  deleteNewHouseFormat,
  queryNewHouseFloorList,
  deleteNewHouseFloor,
  createNewHouseFloor,
  queryNewHouseFloorDetail,
  updateNewHouseFloor
}

